﻿<Window x:Class="S7_GenerateSource.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:DMC.UI="clr-namespace:DMC.UI;assembly=DMC.UI"
        xmlns:sys="clr-namespace:System;assembly=mscorlib"
        xmlns:this="clr-namespace:S7_GenerateSource"
        Height="642" 
        Title="S7 DiffMerge" 
        Width="985" Icon="/S7_GenerateSource;component/DMC%20Siemens%20Icon.ico">
    <Window.Resources>
        <this:S7_ViewModel x:Key="VM"/>
        <this:SeverityToImageConverter x:Key="SeverityToImageConverter" />
        <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
        <this:SimilarityToColorConverter x:Key="SimilarityToColorConverter" />
        <Style TargetType="TextBlock" x:Key="TextBlockHeader1Style">
            <Setter Property="VerticalAlignment" Value="Center" />
            <Setter Property="Foreground" Value="Black" />
            <Setter Property="FontSize" Value="14" />
            <Setter Property="FontWeight" Value="Bold" />
            <Setter Property="Margin" Value="5,0" />
        </Style>
        <this:BlockToCopyEnableConverter x:Key="BlockToCopyEnableConverter" />
        <this:BlockToMergeEnableConverter x:Key="BlockToMergeEnableConverter" />
        <!--<Style TargetType="GroupBox">
            <Setter Property="HeaderTemplate">
                <Setter.Value>
                    <DataTemplate DataType="Header" >
                        <TextBlock Text="{Binding}" Style="{StaticResource TextBlockHeader1Style}" />
                    </DataTemplate>
                </Setter.Value>
            </Setter>
            <Setter Property="Margin" Value="5" />
            <Setter Property="BorderThickness" Value="2" />
        </Style>-->
    </Window.Resources>

    <Grid DataContext="{Binding Source={StaticResource VM}}">
        
        <Grid >
            <DockPanel>
               
                <GroupBox DockPanel.Dock="Top" Header="Projects" >
                    <Grid>
                        
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*" />
                            <ColumnDefinition Width="*" />
                        </Grid.ColumnDefinitions>
                        
                        <Grid Grid.Column="0">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="39" />
                                <ColumnDefinition Width="27" />
                                <ColumnDefinition Width="Auto" />
                                <ColumnDefinition Width="*" />                                
                            </Grid.ColumnDefinitions>
                            <Grid.RowDefinitions>
                                <RowDefinition />
                                <RowDefinition />
                            </Grid.RowDefinitions>                            
                            <TextBlock Margin="5" VerticalAlignment="Center" Text="Left:" Grid.ColumnSpan="2" />
                            <TextBlock Grid.Column="3" Margin="5" VerticalAlignment="Center" Text="{Binding LeftProjectPath}" Grid.ColumnSpan="2" />
                            <Button Grid.Column="2" Content="..." HorizontalAlignment="Left" Command="{Binding Path=BrowseCmd}" CommandParameter="Left" Width="22"/>
                            <TextBlock Grid.Row="1" Margin="5,0" VerticalAlignment="Center" Text="Unpacked:" Visibility="{Binding IsLeftProjectZipped, Converter={StaticResource BooleanToVisibilityConverter}}" Grid.ColumnSpan="2" />
                            <TextBlock Grid.Row="1" Grid.Column="2" Margin="5,0,5,0" Grid.ColumnSpan="2"  VerticalAlignment="Center" Text="{Binding Path=ExtractLeftProjectPath}" Visibility="{Binding IsLeftProjectZipped, Converter={StaticResource BooleanToVisibilityConverter}}" />                            
                        </Grid>


                        <Grid Grid.Column="1">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto" />
                                <ColumnDefinition Width="Auto" />
                                <ColumnDefinition Width="*" />
                            </Grid.ColumnDefinitions>
                            <Grid.RowDefinitions>
                                <RowDefinition />
                                <RowDefinition />
                            </Grid.RowDefinitions>
                            <TextBlock Grid.Row="0" Grid.Column="0" Margin="5" VerticalAlignment="Center" Text="Right:" />
                            <TextBlock Grid.Row="0" Grid.Column="2" Margin="5" VerticalAlignment="Center" Text="{Binding RightProjectPath}" />
                            <Button Grid.Row="0" Grid.Column="1" Content="..." Command="{Binding Path=BrowseCmd}" CommandParameter="Right" Width="22" />
                            <TextBlock Grid.Row="1" Grid.Column="0" VerticalAlignment="Center" Margin="5,0,5,0" Text="Unpacked:" Visibility="{Binding IsRightProjectZipped, Converter={StaticResource BooleanToVisibilityConverter}}" />
                            <TextBlock Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="2" Margin="5,0,5,0" VerticalAlignment="Center" Text="{Binding Path=ExtractRightProjectPath}" Visibility="{Binding IsRightProjectZipped, Converter={StaticResource BooleanToVisibilityConverter}}"/>
                        </Grid>

                    </Grid>
                    
                </GroupBox>
                <Grid DockPanel.Dock="Left">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="*" />
                    </Grid.ColumnDefinitions>
                    
                    <DockPanel Grid.Column="1">
                        <Grid DockPanel.Dock="Bottom" >
                            <Grid.RowDefinitions>
                                <RowDefinition />
                                <RowDefinition />
                            </Grid.RowDefinitions>
                            
                            <DockPanel Height="50" Grid.Row="0" >
                                <Button DockPanel.Dock="Right" Content="Cancel" Command="{Binding CancelCmd}" Width="75" Margin="5" />
                                <Button DockPanel.Dock="Right" Content="Archive&#x0a;(Right)" Command="{Binding SaveCmd}" Width="75" Margin="5" />
                                <Button DockPanel.Dock="Right" Content="Load&#x0a;Projects" Command="{Binding StartCmd}" Width="75" Margin="5" />
                                <Viewbox Height="35" Width="35" >
                                
                                        <DMC.UI:ProgressWheel Visibility="{Binding IsBusy, Converter={StaticResource BooleanToVisibilityConverter}}" Margin="5">
                                        <!--<DMC.UI:ProgressWheel.RenderTransform>
                                            <ScaleTransform ScaleX=".2" ScaleY=".2"></ScaleTransform>
                                        </DMC.UI:ProgressWheel.RenderTransform>-->
                                    </DMC.UI:ProgressWheel>
                                    </Viewbox>
                                
                                <ProgressBar Grid.Column="0" Value="{Binding ProgressBarCurrent}" Maximum="{Binding ProgressBarMax}" Visibility="{Binding IsBusy, Converter={StaticResource BooleanToVisibilityConverter}}" Margin="5"/>
                                
                                
                            </DockPanel>

                            <StatusBar Grid.Row="1" Visibility="Hidden">
                                <StatusBarItem>
                                    <TextBlock Text="{Binding Path=StatusBarText}"></TextBlock>
                                </StatusBarItem>
                            </StatusBar>
                        </Grid>
                        
                        <!--<GroupBox DockPanel.Dock="Right" Header="Messages">-->
                            <Grid>

                                <Grid.RowDefinitions>
                                    <RowDefinition/>
                                    <RowDefinition Height="100"/>
                                </Grid.RowDefinitions>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="*" />
                                    
                                    
                                </Grid.ColumnDefinitions>
                            <GroupBox Name="groupBox"  DockPanel.Dock="Right" Header="Blocks" IsEnabled="{Binding Path=IsNotBusy}">
                                <Grid>
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="*"/>
                                        <RowDefinition Height="20" ></RowDefinition>
                                    </Grid.RowDefinitions>
                                    <DataGrid  Grid.Row="0" DockPanel.Dock="Top"  BorderBrush="#DDDDDD"  Name="dataGrid" HorizontalGridLinesBrush="#DDDDDD" VerticalGridLinesBrush="#DDDDDD" IsReadOnly="True"  Grid.Column="0" AutoGenerateColumns="False" ItemsSource="{Binding AllBlocks}" Margin="5" SelectedItem="{Binding SelectedBlock}" SelectionMode="Single">
                                    <DataGrid.Resources>
                                        <Style TargetType="DataGridCell">
                                            <Style.Triggers>
                                                <!-- Highlight selected rows -->
                                                <Trigger Property="IsSelected" Value="True">
                                                    <Setter Property="Background" Value="Lavender" />
                                                    <Setter Property="BorderBrush" Value="Lavender" />
                                                    <Setter Property="Foreground" Value="Black" />
                                                </Trigger>
                                            </Style.Triggers>
                                            <Setter Property="BorderThickness" Value="0,0,1,1"/>
                                            <Setter Property="BorderBrush" Value="#DDDDDD"/>
                                            <!-- Add some padding around the contents of a cell -->
                                            <Setter Property="Padding" Value="4,3,4,3" />
                                            <Setter Property="Template">
                                                <Setter.Value>
                                                    <ControlTemplate TargetType="DataGridCell">
                                                        <Border Padding="{TemplateBinding Padding}" Background="{TemplateBinding Background}">
                                                            <ContentPresenter />
                                                        </Border>
                                                    </ControlTemplate>
                                                </Setter.Value>
                                            </Setter>

                                        </Style>
                                        <Style x:Key="DataGridGapCell" TargetType="DataGridCell">
                                            <Setter Property="Background" Value="{Binding ElementName=dataGrid, Path=Background}"/>
                                            <Setter Property="BorderThickness" Value="0,0,1,0"/>
                                            <Setter Property="BorderBrush" Value="{Binding ElementName=dataGrid, Path=HorizontalGridLinesBrush}"/>
                                        </Style>
                                        <!-- Gap ColumnHeader Style -->
                                        <Style x:Key="DataGridGapHeader" TargetType="DataGridColumnHeader">
                                            <Setter Property="Background" Value="{Binding ElementName=dataGrid, Path=Background}"/>
                                        </Style>
                                    </DataGrid.Resources>
                                    <DataGrid.Columns>
                                        <DataGridTextColumn Width="1.3*" Header="Name" Binding="{Binding Value.LeftBlock.Name}">
                                            <DataGridTextColumn.ElementStyle>
                                                <Style TargetType="{x:Type TextBlock}">
                                                    <Setter Property="Foreground" Value="{Binding Value.LeftBlock.NameSimilarity, Converter={StaticResource SimilarityToColorConverter}}"/>
                                                </Style>
                                            </DataGridTextColumn.ElementStyle>
                                        </DataGridTextColumn>
                                            <DataGridTextColumn Width="1.3*" Header="Lang" Binding="{Binding Value.LeftBlock.Language}">
                                                <DataGridTextColumn.ElementStyle>
                                                    <Style TargetType="{x:Type TextBlock}">                                                        
                                                    </Style>
                                                </DataGridTextColumn.ElementStyle>
                                            </DataGridTextColumn>
                                            <DataGridTextColumn Width="1*" Header="Size" Binding="{Binding Value.LeftBlock.Size}">
                                            <DataGridTextColumn.ElementStyle>
                                                <Style TargetType="{x:Type TextBlock}">
                                                    <Setter Property="Foreground" Value="{Binding Value.LeftBlock.SizeSimilarity, Converter={StaticResource SimilarityToColorConverter}}"/>
                                                </Style>
                                            </DataGridTextColumn.ElementStyle>
                                        </DataGridTextColumn>
                                        <DataGridTextColumn Width="5*" Header="Symbol" Binding="{Binding Value.LeftBlock.SymbolicName}">
                                            <DataGridTextColumn.ElementStyle>
                                                <Style TargetType="{x:Type TextBlock}">
                                                    <Setter Property="Foreground" Value="{Binding Value.LeftBlock.SymbolicNameSimilarity, Converter={StaticResource SimilarityToColorConverter}}"/>
                                                        <Setter Property="ToolTip" Value="{Binding Key}"/>
                                                    </Style>
                                            </DataGridTextColumn.ElementStyle>
                                        </DataGridTextColumn>
                                        <DataGridTextColumn Width="4*" Header="Modified" Binding="{Binding Value.LeftBlock.Modified}">
                                            <DataGridTextColumn.ElementStyle>
                                                <Style TargetType="{x:Type TextBlock}">
                                                    <Setter Property="Foreground" Value="{Binding Value.LeftBlock.ModifiedSimilarity, Converter={StaticResource SimilarityToColorConverter}}"/>
                                                </Style>
                                            </DataGridTextColumn.ElementStyle>
                                        </DataGridTextColumn>
                                        
                                        <DataGridTemplateColumn Width="50" HeaderStyle="{StaticResource DataGridGapHeader}">
                                                <DataGridTemplateColumn.CellTemplate>
                                                    <DataTemplate>                                                        
                                                        <Grid>
                                                            <Grid.ColumnDefinitions>
                                                                <ColumnDefinition Width="*" />
                                                                <ColumnDefinition Width="*" />
                                                            </Grid.ColumnDefinitions>
                                                            <Button Grid.Column="0" Command="{Binding Source={StaticResource VM}, Path=CopyBlockToRightCmd}" Visibility="{Binding Path=Value.LeftBlock, Converter={StaticResource BlockToCopyEnableConverter}}">
                                                            <Image Source="/S7_GenerateSource;component/Resources/ArrowRight_32x32.png"></Image>
                                                        </Button>
                                                            <Button Grid.Column="1" Command="{Binding Source={StaticResource VM}, Path=MergeBlockToRightCmd}" Visibility="{Binding Path=Value.LeftBlock, Converter={StaticResource BlockToMergeEnableConverter}}">
                                                            <Image Source="/S7_GenerateSource;component/Resources/Mag_32x32.png"></Image>
                                                        </Button>
                                                        </Grid>
                                                    </DataTemplate>                                                    
                                                </DataGridTemplateColumn.CellTemplate>
                                        </DataGridTemplateColumn>

                                        <DataGridTextColumn Width="1.3*" Header="Name" Binding="{Binding Value.RightBlock.Name}">
                                            <DataGridTextColumn.ElementStyle>
                                                <Style TargetType="{x:Type TextBlock}">
                                                    <Setter Property="Foreground" Value="{Binding Value.RightBlock.NameSimilarity, Converter={StaticResource SimilarityToColorConverter}}"/>
                                                </Style>
                                            </DataGridTextColumn.ElementStyle>
                                        </DataGridTextColumn>
                                            <DataGridTextColumn Width="1.3*" Header="Lang" Binding="{Binding Value.RightBlock.Language}">
                                                <DataGridTextColumn.ElementStyle>
                                                    <Style TargetType="{x:Type TextBlock}">
                                                    </Style>
                                                </DataGridTextColumn.ElementStyle>
                                            </DataGridTextColumn>
                                            <DataGridTextColumn Width="1*" Header="Size" Binding="{Binding Value.RightBlock.Size}">
                                            <DataGridTextColumn.ElementStyle>
                                                <Style TargetType="{x:Type TextBlock}">
                                                    <Setter Property="Foreground" Value="{Binding Value.RightBlock.SizeSimilarity, Converter={StaticResource SimilarityToColorConverter}}"/>
                                                </Style>
                                            </DataGridTextColumn.ElementStyle>
                                        </DataGridTextColumn>
                                        <DataGridTextColumn Width="5*" Header="Symbol" Binding="{Binding Value.RightBlock.SymbolicName}">
                                            <DataGridTextColumn.ElementStyle>
                                                <Style TargetType="{x:Type TextBlock}">
                                                    <Setter Property="Foreground" Value="{Binding Value.RightBlock.SymbolicNameSimilarity, Converter={StaticResource SimilarityToColorConverter}}"/>
                                                        <Setter Property="ToolTip" Value="{Binding Key}"/>
                                                    </Style>
                                            </DataGridTextColumn.ElementStyle>
                                        </DataGridTextColumn>
                                        <DataGridTextColumn Width="4*" Header="Modified" Binding="{Binding Value.RightBlock.Modified}">
                                            <DataGridTextColumn.ElementStyle>
                                                <Style TargetType="{x:Type TextBlock}">
                                                    <Setter Property="Foreground" Value="{Binding Value.RightBlock.ModifiedSimilarity, Converter={StaticResource SimilarityToColorConverter}}"/>
                                                </Style>
                                            </DataGridTextColumn.ElementStyle>
                                        </DataGridTextColumn>
                                    </DataGrid.Columns>
                                </DataGrid>
                                    <Grid Grid.Row="1" DockPanel.Dock="Bottom" Width="50" Height="20" VerticalAlignment="Bottom" HorizontalAlignment="Left">
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition/>
                                            <ColumnDefinition/>
                                        </Grid.ColumnDefinitions>
                                    <ToggleButton Grid.Column="1" IsChecked="{Binding OrphanFilter}"  HorizontalAlignment="Left" VerticalAlignment="Bottom" Width="20" Height="20">
                                        <StackPanel>
                                            <Image Source="/S7_GenerateSource;component/Resources/blue%20filter.png" />
                                        </StackPanel>
                                    </ToggleButton>
                                    <ToggleButton Grid.Column="0" IsChecked="{Binding DifferenceFilter}" HorizontalAlignment="Left" VerticalAlignment="Bottom" Width="20" Height="20">
                                        <StackPanel>
                                            <Image Source="/S7_GenerateSource;component/Resources/red%20filter.png" />
                                        </StackPanel>
                                    </ToggleButton>
                                    </Grid>
                                </Grid>
                            </GroupBox>

                            <ListView ItemsSource="{Binding LogEvents}" Margin="5" Grid.ColumnSpan="3" Grid.Row="1" DMC.UI:ListBoxExtenders.AutoScrollToEnd="True">
                                    
                                    <ListView.ItemTemplate>
                                        <DataTemplate>
                                            <Grid>
                                                <Grid.ColumnDefinitions>
                                                    <ColumnDefinition Width="Auto" />
                                                    <ColumnDefinition Width="Auto" />
                                                    <ColumnDefinition Width="*" />
                                                </Grid.ColumnDefinitions>
                                                <Image Grid.Column="0" Height="16" Width="16" Source="{Binding Path=LogSeverity, Converter={StaticResource SeverityToImageConverter}}" Margin="5,1" />
                                                <TextBlock Grid.Column="1" Text="{Binding Timestamp}" VerticalAlignment="Center" Margin="5,1" />
                                                <TextBlock Grid.Column="2" Text="{Binding Message}" VerticalAlignment="Center" Margin="5,1" />
                                            </Grid>
                                        </DataTemplate>
                                    </ListView.ItemTemplate>
                                </ListView>
                                
                            
                            
                        </Grid>
                            
                        <!--</GroupBox>-->
                        
                    </DockPanel>
                </Grid>
            </DockPanel>
        </Grid>
        
    </Grid>
</Window>
